package net.news.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;

import net.news.entity.NewsPeople;
import net.news.service.NewsPeopleService;

import com.liesp.util.ConstantUtils;
import com.liesp.util.PropertyFilter;
import com.livesky.framework.miniapp.ActionSupport;
import com.livesky.framework.miniapp.utils.ViewUtils;

/**
 * 项目名称：cmunews3084<br>
 * 类名称：LoginUserAction <br>
 * 类描述： TODO(请输入类的描述) <br>
 * 创建人：charles 创建时间：2011-5-10 下午10:57:54 <br>
 * 修改人： 修改时间： <br>
 * 修改备注：
 * 
 * @version V1.0
 */
@Controller
public class LoginUserAction extends ActionSupport {
	private NewsPeople newsPeople = new NewsPeople();
	private List<NewsPeople> newsPeoples;
	@Resource
	private NewsPeopleService newsPeopleService;

	/** 
	 * 初始页面方法
	 * 
	 * @return
	 */
	public String index() {
		return SUCCESS;
	}
	
	/**
	 * 登录方法
	 * 
	 * @return
	 */
	public String login() {
		if (newsPeople.getName() != null&&newsPeople.getPsw()!=null&&!newsPeople.getName().equals("")&&!newsPeople.getPsw().equals("")) {
			newsPeople = newsPeopleService.userLogin(newsPeople);
			if(newsPeople!=null){
				HttpSession hsHttpSession = ViewUtils.getRequest().getSession();
				hsHttpSession.setAttribute(ConstantUtils.USER_LOGIN_SESSIOIN,
						newsPeople);
				return "r:/first_page/backstage/";
			}
		}
		ViewUtils.renderScript("alert('用户名或密码错误！');history.back()");
		return null;
	}

	/**
	 * 编辑人员方法
	 * 
	 * @return
	 */
	public String viewPeople() {
		newsPeople = newsPeopleService.getNewsPeople(newsPeople);
		return SUCCESS;
	}

	/**
	 * 修改人员方法
	 * 
	 * @return
	 */
	public String modifyNewsP() {
		newsPeopleService.modifyNewsPeople(newsPeople);
		return "r:full_news_people";
	}

	/**
	 * 进入新增管理员页面方法
	 * 
	 * @return
	 */
	public String viewgetPeople() {
		return SUCCESS;
	}

	/**
	 * 增加管理员方法
	 * 
	 * @return
	 */
	public String addPeople() {
		newsPeopleService.addNewsPeoPle(newsPeople);
		return "r:full_news_people";
	}

	/**
	 * 判断用户是否存在
	 * 
	 * @return
	 */
	public String booleanNewsPeople() {
		boolean stat = newsPeopleService.getNewsPeopleBoolean(newsPeople);
		String str = stat == false ? "false" : "true";
		ViewUtils.renderText(str);
		return null;
	}

	/**
	 * 模糊查询管理员方法
	 * 
	 * @return
	 */
	public String fullNewsPeople() {
		List<PropertyFilter> filters = PropertyFilter
				.buildFromHttpRequest(ViewUtils.getRequest());
		newsPeoples = newsPeopleService.getNpList(filters);
		return SUCCESS;
	}

	/**
	 * 删除管理员方法
	 * 
	 * @return
	 */
	public String deltenewspeople() {
		newsPeopleService.deleteNewsPeople(newsPeople);
		return "r:full_news_people";
	}

	/**
	 * @return the newsPeople
	 */
	public NewsPeople getNewsPeople() {
		return newsPeople;
	}

	/**
	 * @param newsPeople
	 *            the newsPeople to set
	 */
	public void setNewsPeople(NewsPeople newsPeople) {
		this.newsPeople = newsPeople;
	}

	/**
	 * @return the newsPeoples
	 */
	public List<NewsPeople> getNewsPeoples() {
		return newsPeoples;
	}

	/**
	 * @param newsPeoples
	 *            the newsPeoples to set
	 */
	public void setNewsPeoples(List<NewsPeople> newsPeoples) {
		this.newsPeoples = newsPeoples;
	}

}
